<?php
/**
 * Created by PhpStorm.
 * User: luzy
 * Date: 2018/7/12
 * Time: 下午3:54
 */

class Wenjuan_model extends Base_Model
{
    public function __construct()
    {
        parent::__construct();
        $this->load->database();
    }

    public function getWenjuanqListData($controller,$where=array(),$limit=10,$offset=0)
    {
        $this->db->from('wenjuan_question');
        if (!empty($where)) $this->db->where($where);
        $data=$this->db->order_by('sort ASC')->limit($limit,$offset)
            ->get()->result_array();
        $res = array();
        foreach ($data as $row){
            $resrow = array();
            $resrow[] = $row['question'];
            $resrow[] = $row['sort'];
            $resrow[] = $this->getWenjuanGroupName($row['wenjuangroupid']);
            $actionlist ='<a class="eidt-btn action-btn" href="'.site_url($controller).'update/'.$row['id'].'">修改</a>';
            $actionlist .= '<a class="other-btn action-btn" href="'.site_url('admin/wenjuanitem/').'showlist/'.$row['id'].'/1">问题选项</a>';
            $resrow[] = $actionlist;
            $res[] = $resrow;
        }
        return $res;
    }

    public function getWenjuanGroupName($gid)
    {
        $res = $this->db->select('name')->from('wenjuan_group')->where('id',$gid)->get()->row_array();
        return $res['name'];

    }

    public function getWenjuanGroupList()
    {
        $res = $this->db->select('id,name')->from('wenjuan_group')->order_by('id DESC')->get()->result_array();
        $data = array();
        foreach ($res as $row){
            $data[$row['id']]=$row['name'];
        }
        return $data;
    }

    public function getQuestion($qid)
    {
        $res = $this->db->select('question')->from('wenjuan_question')->where('id',$qid)->get()->row_array();
        return $res['question'];
    }

}